package com.bojx.cms.service;

import java.util.List;

import com.bojx.cms.dao.ArticleDao;
import com.jfinal.kit.StrKit;
import com.jfinal.plugin.activerecord.Record;

public class ArticleService {
	private static ArticleDao articleDao=new ArticleDao();
	public long count(String keyword){
		 if(StrKit.isBlank(keyword)){
			 return articleDao.queryCount();
		 }else{
			 return articleDao.queryCount(keyword);
		 }
	     
	}
	
	
	
	
	public List<Record> queryArticles(long pageNum,String keyword){
		int start=(int) ((pageNum-1)*20);
		int end=(int)pageNum*20-1;
		if(StrKit.isBlank(keyword)){
			return articleDao.queryArticles(start,end);
		}else{
			return articleDao.queryArticles(start,end,keyword);
		}
	}
	
	public Record findArticleById(long id) throws Exception{
		Record result=articleDao.queryArticleById(id);
		if(result==null){
			throw new Exception("没有这条记录");
		}
		
		return result;
	}
}
